﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HomeWork11
{
    class Program
    {
        static void Main(string[] args)
        {
            using(var context =new TestContext())
            {
                var booklist = new BookList { BookListID=1 };
                booklist.Books = new List<Book>() {
          new Book() { BookID=0,AuthorName="Su" },
          new Book() { BookID=1,AuthorName="Hu"}
        };
                context.BookLists.Add(booklist);
                context.SaveChanges();
            }
         
            using (var context=new TestContext())
            {
                var book = new Book { BookID = 10, BookListID = 1, BookName = "World" };
                context.Books.Add(book);
                context.SaveChanges();
            }
            using (var context = new TestContext())
            {
                var blog = context.BookLists
                    .SingleOrDefault(b => b.BookListID == 1);
                if (blog != null) Console.WriteLine(blog.Books.
                    SingleOrDefault(b=>b.BookID==1).BookID);
            }
        }
    }
}
